﻿@inherits BaseComponent

<CmsCard>
    @if (CurrentUser == null)
    {
        <div style="color:#252933;font-size:16px;font-weight:bold;">@greeting</div>
    }
    else
    {
        <div class="cl-sign-box">
            <div class="user">
                <a href="@Url.UserCreatorUrl">
                    <AntAvatar Src="@CurrentUser?.AvatarUrl" />
                    <span>@CurrentUser?.Name</span>
                </a>
            </div>
            <div>
                <AntButton Name="去提问" OnClick="@($"location='{Url.PostFormUrl}'")" />
            </div>
        </div>
        <div class="cl-sign-bottom">
            <span><span class="qty-count">@user?.ContentQty</span> 问题</span>
            <span class="divider">|</span>
            <span><span class="qty-count">@user?.ReplyQty</span> 回复</span>
        </div>
    }
</CmsCard>

@code {
    private string greeting;
    private CmUser user = new();

    [Parameter] public ISiteService Service { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        greeting = GetGreeting();
        if (CurrentUser != null)
            user = await Service.GetUserAsync(CurrentUser.Id);
    }

    private string GetGreeting()
    {
        var hour = DateTime.Now.Hour;
        if (hour > 5 && hour <= 12)
            return "上午好！";
        else if (hour > 12 && hour < 18)
            return "下午好！";
        else
            return "晚上好！";
    }
}